home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-03-14 | 5.5 KB | 147 lines | [TEXT/CCL2] |
- ;;;
- ;;; compare-windows.lisp
- ;;;
-
- #|
- ================================================================
- Purpose ========================================================
- ================================================================
- Implements a simple but very handy incremental compare feature. Works on
- the top two Fred windows.
-
- Copyright © 1990-92 Matthew Cornell. All Rights Reserved. Send
- bugs, comments, questions, and fixes to cornell@cs.umass.edu.
-
-
- ================================================================
- Status =========================================================
- ================================================================
- Implemented.
-
-
- ================================================================
- Change history =================================================
- (ds = Dan Suthers/UMASS, mc = Matthew Cornell, kp Karsten Poeck)
- ================================================================
- ?? mc Created.
- 15-Jan-90 ds Put it in Edit menu with different name.
- 30-Jan-90 ds Changed window-draw-contents to view-draw-contents for version
- 1.3.1.
- 20-Apr-90 mc Added command-key binding for the menu item.
- 24-Apr-90 mc Fixed getting the windows to scroll to show the insertion
- bar once it's moved.
- Distributed to public domain.
- 30-Jan-90 ds Added PROVIDE :COMPARE-WINDOWS.
- 4-July-91 kp Ported to MACL 2.0b1
- 2-Mar-92 mc Fixed to work with mcl2.0f2 .
-
- |#
-
-
- (in-package "COMMON-LISP-USER")
-
-
- (defun compare-windows
- (&key (w1 (first (select-item-from-list (windows :class 'fred-window)
- :window-title "Select compare window 1")))
- (w2 (first (select-item-from-list (windows :class 'fred-window)
- :window-title "Select compare window 2")))
- (skip-white? t))
- "Moves each window's cursor mark along if they point to the same character,
- skipping whitespace. Stops at the point where they are off, allowing the user
- to
- resynchronize and start again manually. Beeps if it fails (right?)."
- ;;
- (labels ((REMOVE-WHITESPACE (buffer mark size)
- "Moves <mark> along until it doesn't point to whitespace (tab,
- space, or non-breaking white/decimal 202)."
- (do ()
- ((or (= (buffer-position mark) size) ;avoids a nasty error
- (not (ccl:whitespacep (buffer-char buffer mark)))))
- (move-mark mark)))
- (NOT-EQUAL-HERE? (w1-buf w1-mark w2-buf w2-mark)
- "Returns t if w1 and w2 don't point to the same character."
- (char-not-equal (buffer-char w1-buf w1-mark)
- (buffer-char w2-buf w2-mark))))
- (let* ((w1-buf (fred-buffer w1))
- (w1-mark w1-buf)
- (w1-size (buffer-size w1-buf))
- (w2-buf (fred-buffer w2))
- (w2-mark w2-buf)
- (w2-size (buffer-size w2-buf)))
- (loop (when skip-white?
- (REMOVE-WHITESPACE w1-buf w1-mark w1-size)
- (REMOVE-WHITESPACE w2-buf w2-mark w2-size))
- ;;
- (cond ((or (= (buffer-position w1-mark) w1-size)
- (= (buffer-position w2-mark) w2-size))
- ;; someone reached the end so test if sucessful
- (cond ((and (= (buffer-position w1-mark) w1-size)
- (= (buffer-position w2-mark) w2-size))
- ;; Made it! (they're equal).
- (return t))
- (t ;they're not equal (sob)
- (ed-beep)
- (return nil))))
- ((NOT-EQUAL-HERE? w1-buf w1-mark w2-buf w2-mark)
- ;; They're not equal (sob).
- (ed-beep)
- (return nil))
- (t ;check the next ones
- (move-mark w1-mark)
- (move-mark w2-mark))))
- ;; get the flashy insert bar to show in new position
- (set-mark (fred-display-start-mark w1) (buffer-position (fred-buffer w1)))
- (fred-update w1)
- (set-mark (fred-display-start-mark w2) (buffer-position (fred-buffer w2)))
- (fred-update w2))))
-
-
- ;;; the menu stuff
-
- (defclass *compare-menu-item* (menu-item)
- ())
-
-
- (defmethod initialize-instance ((ich *compare-menu-item* ) &rest init-list)
- (apply #'call-next-method ich
- (init-list-default
- init-list
- :menu-item-title "Compare Top Windows"
- :command-key #\h
- :menu-item-action
- #'(lambda ()
- (compare-windows
- :w1 (first (windows)) :w2 (second (windows))
- :skip-white? (find-menu-item *edit-menu*
- "Compare Top Windows (Skip)"))))))
-
- (defmethod menu-item-update ((ich *compare-menu-item*))
- "Disables the item if the top two windows aren't *fred-window*s and
- changes the title (if the option key is down) to 'Compare Top Windows (Skip)'"
- ;;
- (if (and (typep (first (windows)) 'fred-window)
- (typep (second (windows)) 'fred-window))
- (menu-item-enable ich)
- (menu-item-disable ich))
- ;;
- (if (option-key-p)
- (set-menu-item-title ich "Compare Top Windows (Skip)")
- (set-menu-item-title ich "Compare Top Windows")))
-
-
- ;;;
- ;;; Add the menu item.
- ;;;
-
- (progn
- (dolist (menu-item (menu-items *edit-menu*))
- (when (typep menu-item '*compare-menu-item*)
- (remove-menu-items *edit-menu* menu-item)))
- (add-menu-items *edit-menu* (make-instance '*compare-menu-item*)))
-
-
-
- (provide :compare-windows)
-
- ;;; The End.